<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cache Groups</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="caching.html" title="Chapter 15. Caching">
<link rel="prev" href="caching.multiple.caches.html" title="Multiple Caches Per Page">
<link rel="next" href="caching.cacheable.html" title="Controlling Cacheability of Output">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Cache Groups</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="caching.multiple.caches.html">Prev</a> </td>
<th width="60%" align="center">Chapter 15. Caching</th>
<td width="20%" align="right"> <a accesskey="n" href="caching.cacheable.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Cache Groups">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="caching.groups"></a>Cache Groups</h2></div></div></div>
<p>
      You can do more elaborate grouping by setting up
      <em class="parameter"><code>$cache_id</code></em> groups. This is
      accomplished by separating each sub-group with a vertical bar
      <code class="literal">|</code> in the <em class="parameter"><code>$cache_id</code></em> value.
      You can have as many sub-groups as you like.
     </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
      You can think of cache groups like a directory hierarchy. For instance, a
      cache group of <code class="literal">'a|b|c'</code> could be thought of as the
      directory structure <code class="literal">'/a/b/c/'</code>.
      </p></li>
<li class="listitem"><p>
      <code class="literal">clearCache(null,'a|b|c')</code>
      would be like removing the files
      <code class="literal">'/a/b/c/*'</code>. <code class="literal">clearCache(null,'a|b')</code>
      would be like removing the files <code class="literal">'/a/b/*'</code>.
      </p></li>
<li class="listitem"><p>
      If you specify a
      <a class="link" href="variable.compile.id.html" title="$compile_id"><em class="parameter"><code>$compile_id</code></em></a>
      such as <code class="literal">clearCache(null,'a|b','foo')</code> it is treated as
      an appended cache group <code class="literal">'/a/b/c/foo/'</code>.
      </p></li>
<li class="listitem"><p>
      If you specify a template name such as
      <code class="literal">clearCache('foo.tpl','a|b|c')</code> then Smarty will attempt
      to remove <code class="literal">'/a/b/c/foo.tpl'</code>.
      </p></li>
<li class="listitem"><p>
      You CANNOT remove a specified template name under
      multiple cache groups such as <code class="literal">'/a/b/*/foo.tpl'</code>, the
      cache grouping works
      left-to-right ONLY. You will need to group your templates under a single
      cache group heirarchy to be able to clear them as a group.
     </p></li>
</ul></div>
<p>
      Cache grouping should not be confused with your template directory
      heirarchy, the cache grouping has no knowledge of how your templates are
      structured. So for example, if you have a template structure like
      <code class="filename">themes/blue/index.tpl</code> and you want to be able to
      clear all the cache files for the <span class="quote">“<span class="quote">blue</span>”</span> theme, you will need
      to create a cache group
      structure that mimics your template file structure, such as
      <code class="literal">display('themes/blue/index.tpl','themes|blue')</code>, then
      clear them with
      <code class="literal">clearCache(null,'themes|blue')</code>.
     </p>
<div class="example">
<a name="id451968"></a><p class="title"><b>Example 15.9. $cache_id groups</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
require('Smarty.class.php');
$smarty = new Smarty;

$smarty-&gt;setCaching(Smarty::CACHING_LIFETIME_CURRENT);

// clear all caches with 'sports|basketball' as the first two cache_id groups
$smarty-&gt;clearCache(null,'sports|basketball');

// clear all caches with "sports" as the first cache_id group. This would
// include "sports|basketball", or "sports|(anything)|(anything)|(anything)|..."
$smarty-&gt;clearCache(null,'sports');

// clear the foo.tpl cache file with "sports|basketball" as the cache_id
$smarty-&gt;clearCache('foo.tpl','sports|basketball');


$smarty-&gt;display('index.tpl','sports|basketball');
?&gt;

      </pre></div>
</div>
<br class="example-break">
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="caching.multiple.caches.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="caching.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="caching.cacheable.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Multiple Caches Per Page </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Controlling Cacheability of Output</td>
</tr>
</table>
</div>
</body>
</html>
